//package cn.wolfcode.web.controller;
//
//import cn.wolfcode.domain.Department;
//import cn.wolfcode.qo.JsonResult;
//import cn.wolfcode.service.IDepartmentService;
//import com.alibaba.fastjson.JSON;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.ModelAttribute;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import javax.servlet.http.HttpServletResponse;
//import java.util.Date;
//import java.util.List;
//
//@Controller
//public class JsonController {
//
//    @Autowired
//    private IDepartmentService departmentService;
//
//    //若形参有一个类型response , 方法返回值可以是void
////    @RequestMapping("/getTime")
////    public void getTime(HttpServletResponse response) throws Exception {
////        //相应Html格式内容给浏览器
////        /*response.setContentType("text/html;charset=utf-8");
////        PrintWriter writer = response.getWriter();
////        writer.write("Html格式");
////        writer.flush();*/
////
////        //响应JSON格式内容给浏览器
////        response.setContentType("application/json;charset=utf-8");
////        PrintWriter writer = response.getWriter();
////        Date date = new Date();
////        JsonResult jsonResult = new JsonResult();
////        jsonResult.setSuccess(true);
////        jsonResult.setMsg(date.toLocaleString());
////        //FastSon转成java对象
////        writer.write(JSON.toJSONString(jsonResult));//避免自己拼接字符串
////        writer.flush();
////    }
//
//    @RequestMapping("/getTime2")
//    @ResponseBody
//    public JsonResult getTime2(HttpServletResponse response) throws Exception {
//        //相应Html格式内容给浏览器
//        /*response.setContentType("text/html;charset=utf-8");
//        PrintWriter writer = response.getWriter();
//        writer.write("Html格式");
//        writer.flush();*/
//
//        //响应JSON格式内容给浏览器
//        //response.setContentType("application/json;charset=utf-8");
//        //PrintWriter writer = response.getWriter();
//        Date date = new Date();
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.setSuccess(true);
//        jsonResult.setMsg(date.toLocaleString());
//        //FastSon转成java对象
//        //writer.write(JSON.toJSONString(jsonResult));
//        return jsonResult;
//    }
//
//
//    @RequestMapping("/depts")
//    @ResponseBody
//    public List<Department> getDepts() {
//        return departmentService.listAll();
//    }
//
//    @RequestMapping("/checkUsername")
//    @ResponseBody
//    public JsonResult checkUsername(String username) {
//        //数据库查询,模仿一下lony
//        JsonResult jsonResult = new JsonResult();
//        if ("lony".equals(username)) {
//            jsonResult.setSuccess(false);
//            jsonResult.setMsg("用户名已注册");
//        } else {
//            jsonResult.setMsg("去注册把");
//            jsonResult.setSuccess(true);
//        }
//        return jsonResult;
//    }
//
//    @RequestMapping("/login")
//    @ResponseBody
//    public JsonResult login(String username, String password) {
//        //数据库查询,模仿一下lony
//        JsonResult jsonResult = new JsonResult();
//        if ("lony".equals(username) && "1".equals(password)) {
//            jsonResult.setSuccess(true);
//            jsonResult.setMsg("登录成功");
//        } else {
//            jsonResult.setMsg("用户名或者密码错误");
//            jsonResult.setSuccess(false);
//        }
//        return jsonResult;
//    }
//
//
//}
